<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <meta name="referrer" content="no-referrer">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        img{
            width:60px;
        }
        td{
            width: 260px;
        }
    </style>
</head>
<body>
    <!-- <div id="app">
        {{each data}}
            {{$value}}
        {{/each}}
    </div> -->

    <div id="app">
        <h2>豆瓣Top250</h2>
        {{each res}}
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>名字</th>
                    <th>海报</th>
                    <th>评分</th>
                    <th>是否收藏</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>{{$value._id}}</td>
                    <td>{{$value.title}}</td>
                    <td>
                        <a href="./detail?id={{@$value._id}}"><img src="{{$value.pic}}" alt=""></a>
                    </td>
                    <td>{{$value.rating}}</td>
                    <td>
                        
                        <a href="{{$value.collected?'/cancel':'/collect'}}?id={{@$value._id}}">
                            <img src="{{$value.collected?'../public/collect.png':'../public/cancel.png'}}" alt="">
                        </a>
                    </td>
                    <td>
                        <a href="/delete?id={{@$value._id}}">
                            <button class="btn btn-danger">删除</button>
                        </a>
                    </td>
                </tr>
            </tbody>
        </table>
        {{/each}}
        <nav aria-label="Page navigation" class="text-center">
            <ul class="pagination pagination-lg">
            <li>
            <a href="./?start={{previous}}" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
            </li>
            <li  v-for="item of pages">
                {{each result}}
                <!-- <form action="/top250"> -->
                    <!-- <input type="hidden" name="start" value="{{$value}}"> -->
                <a  href="./?start={{$value}}" href="javascript:void(0)">{{$value}}</a>
                <!-- </form> -->
                {{/each}}
            </li>
            <li>
            <a href="./?start={{next}}" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
            </a>
            </li>
        </ul>
        </nav>
    </div>
</body>

computed:{
    pages:function(){
        /*
        23
        [0,5,10,15,20]
        （item+5)/5
        [1,2,3,4,5] 
         */
        var total = this.total;
        var arr = [];
        for(var i=0;i<total;i+=5){
            arr.push(i);
        }
        var res = arr.map(item=>{
            return (item+5)/5
        })
        return res;
    }
}
})
</html>